package com.dycx.message.enums;

import lombok.Getter;

import java.util.*;

/**
 * @author 消息类型
 * @date 2023/2/23
 */
@Getter
public enum MessageTypeEnum {
    ALIYU_SMS(10, "阿里云短信"),
    WX_MP(20, "微信公众号模版消息");

    private final Integer code;
    private final String name;

    MessageTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String converter(Integer code) {
        return Arrays.stream(values()).filter(en -> en.code.equals(code)).findAny().orElse(ALIYU_SMS).getName();
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (MessageTypeEnum item : MessageTypeEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode().toString());
            map.put("name", item.getName());
            list.add(map);
        }
        return list;
    }
}
